package com.vm.adapter;

import java.util.List;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.vm.commons.VMConst;
import com.vm.model.UserOrder;
import com.vm.utils.MyDisplayImageOptions;
import com.wwtscapp.apk.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.View.OnClickListener;

/**
 * 
 * @ProjectName: [WeiMai]
 * @Author: [kent.wang]
 * @CreateDate: [2015年1月24日 上午10:01:01]
 * @Version: [v1.0]
 * 
 */

@SuppressLint("InflateParams")
public class OrderAdapter extends BaseAdapter {

	private static final String TAG = "PresentAdapter";
	private Context mContext;
	private List<UserOrder> listOrders;

	/**
	 * 
	 */
	public OrderAdapter(Context context, List<UserOrder> lists) {
		this.mContext = context;
		this.listOrders = lists;

	}

	@Override
	public int getCount() {
		return listOrders.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = null;
		if (convertView == null) {

			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.order_item, null);
			viewHolder = new ViewHolder();

			/**
			 * 获取各个需要显示属性的控件
			 */
			viewHolder.iv_goodsImage = (ImageView) convertView
					.findViewById(R.id.iv_goodsImage);
			// viewHolder.tv_goodsName = (TextView) convertView
			// .findViewById(R.id.tv_goodsName);
			viewHolder.tv_time = (TextView) convertView
					.findViewById(R.id.tv_time);
			viewHolder.tv_order_number = (TextView) convertView
					.findViewById(R.id.tv_order_number);
			viewHolder.tv_integra_num = (TextView) convertView
					.findViewById(R.id.tv_integra_num);
			viewHolder.tv_goods_number = (TextView) convertView
					.findViewById(R.id.tv_goods_number);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		UserOrder userOrder = listOrders.get(position);
		Log.i(TAG, Integer.toString(position));
		// viewHolder.tv_goodsName.setTag(userOrder.getId());
		// viewHolder.tv_goodsName.setText(userOrder.getName());
		// viewHolder.tv_integra_num.setText(Integer.toString(userOrder
		// .getIntegral()));
		viewHolder.tv_time.setText(userOrder.getOrderTime());
		viewHolder.tv_order_number.setText(userOrder.getId());
		if (userOrder.getIntegral() != null) {
			viewHolder.tv_integra_num.setText(Integer.toString(userOrder
					.getIntegral()));
		} else {
			viewHolder.tv_integra_num.setText("0");
		}
		if (userOrder.getNumber() != null) {
			viewHolder.tv_goods_number.setText(Integer.toString(userOrder
					.getNumber()));
		}
		String url = VMConst.URL + userOrder.getImageUrl();
		ImageLoader.getInstance().displayImage(url, viewHolder.iv_goodsImage,
				MyDisplayImageOptions.getInstance());

		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Intent intent = new Intent(v.getContext(),
				// GoodsDetailActivity.class);
				// intent.putExtra("goodsId", userOrder.getGoodsId());
				// v.getContext().startActivity(intent);
			}
		});
		return convertView;

	}

	static class ViewHolder {
		TextView tv_time;
		TextView tv_order_number;
		TextView tv_goods_number;
		TextView tv_goodsName;
		ImageView iv_goodsImage;
		TextView tv_integra_num;
	}

}
